<template>
	<w-layout showNavbar navTitle="VIP 签到" :navTitleColor="publicStyles['--color-t1']" background="url('/static/image/bk.png') no-repeat"
		navBackgroundColor="transparent" :scrollTop="page.scrollTop" :navScrollColor="publicStyles['--color-bk']">
		<template #default>
			<view class="container">
				<view class="public-box-5 px-50 pt-100 pb-60 fc" style="min-height: 700rpx;">
					<view class="color fs-36">
						<text>尊贵的</text><text class="ml-10">VIP{{state.vip_info.title}} 用户</text>
					</view>
					<view class="fr-ac-jc mt-80">
						<view class="mr-10 op-70 fs-26">
							当前签到可获得
						</view>
					</view>
					<view class="fr-ac-jsa mt-70">
						<view class="fc-ac">
							<image style="width: 112rpx;height: 112rpx;" src="/src/static/icon/public/yuan-bao.png" mode="widthFix"></image>
							<view class="mt-10">
								精粹x{{state.vip_info.integral}}
							</view>
						</view>
						<view class="fc-ac">
							<image style="width: 112rpx;height: 112rpx;" src="/src/static/icon/public/yuan-qi.png" mode="widthFix"></image>
							<view class="mt-10">
								精气x{{state.vip_info.score}}
							</view>
						</view>
					</view>
					
					<view @click="receive" class="public-btn-3 transition px-30 py-25 t-c mt-auto">
						<view class="text-color-b fs-32">
							立即领取
						</view>
					</view>
				</view>
				<view class="public-box-3 px-50 py-50 mt-40" style="min-height: 750rpx;">
					<view class="color fs-36">
						<text>规则说明</text>
					</view>
					<view class="mt-30 op-70" style="line-height: 1.8;max-height: 600rpx;overflow: scroll;">
						<up-parse :content="state.content"></up-parse>
					</view>
				</view>
				
				<up-popup :show="popup.showSign" @close="popup.showSign=false" mode="center" :safeAreaInsetBottom="false" bgColor="transparent">
					<view class="public-popup-2 px-50 py-20 fc" style="width: 670rpx;min-height: 760rpx;position: relative;">
						<view class="fs-36">
							恭喜获得
						</view>
						<view class="mt-100 fc-ac">
							<view class="public-cover-2 t-c fs-36" style="width: 360rpx;height: 70rpx;">
							</view>
							<view class="fr-ac-jsa w-100 mt-70">
								<view class="fc-ac">
									<image style="width: 112rpx;height: 112rpx;" src="/src/static/icon/public/yuan-bao.png" mode="widthFix"></image>
									<view class="mt-10">
										精粹x{{state.vip_info.integral}}
									</view>
								</view>
								<view class="fc-ac">
									<image style="width: 112rpx;height: 112rpx;" src="/src/static/icon/public/yuan-qi.png" mode="widthFix"></image>
									<view class="mt-10">
										精气x{{state.vip_info.score}}
									</view>
								</view>
							</view>
						</view>
						<view @click="popup.showSign = false" class="public-btn-3 transition py-25 t-c mt-auto mb-60">
							<view class="text-color-b fs-32">
								确定
							</view>
						</view>
					</view>
				</up-popup>
				
			</view>
		</template>
	</w-layout>
</template>

<script setup>
	import {
		ref,
		reactive,
		onMounted,
		computed,
		nextTick
	} from 'vue'
	import {
		storeToRefs
	} from 'pinia'
	import {
		onLoad, onPageScroll
	} from '@dcloudio/uni-app'
	import {
		useAppStore
	} from '@/store/app'
	import {
		useColorStore
	} from '@/store/color'
	import {
		get_parse,
		vip_sign_info,
		vip_sign
	} from '@/utils/request/api';
	import {
		useUserStore
	} from '@/store/user'
	const userStore = useUserStore()
	const appStore = useAppStore()
	const colorStore = useColorStore()
	const {
		publicStyles
	} = storeToRefs(colorStore)
	onLoad(async(options) => {
		get_parseApi(9)
		get_vip_sign_info()
	})
	onMounted(() => {
		appStore.loadingHandler(false)
	})
	onPageScroll((e)=>{
		page.scrollTop = e.scrollTop
	})
	const page = reactive({
		scrollTop:0
	})
	
	const popup = reactive({
		showSign:false,
	})
	
	const state = reactive({
		content:'',
		vip_info:{},
		vip_level_info:{},
	})
	async function get_parseApi(type){
		const res = await get_parse({
			type
		})
		state.content = res
	}
	async function get_vip_sign_info(){
		const res = await vip_sign_info({})
		if(res.vip_info){
			state.vip_info = res.vip_info
			state.vip_level_info = res.vip_level_info
		}else{
			uni.$u.toast('您不是VIP')
			setTimeout(()=>{
				uni.navigateBack()
			},1000)
		}
	}
	async function receive(){
		const res = await vip_sign({})
		uni.$u.toast('领取成功！')
		popup.showSign = true
	}
</script>

<style lang="scss">
	.shadow {
		box-shadow: 2rpx 2rpx 12rpx var(--shadow);
	}
	.color{
		color: var(--color);
	}

	.container {
		width: 100%;
		min-height: 100%;
		position: relative;
		overflow: hidden;
		box-sizing: border-box;
		padding: 50rpx;
		
	}
	
	.login-btn {
		color: white !important;
		background: var(--color) !important;
		border-radius: 12rpx !important;
	}
</style>